package com.mck.controller;

import com.mck.entity.Result;
import com.mck.entity.UserClassname;
import com.mck.entity.Classname;
import com.mck.entity.User;
import com.mck.service.UserClassnameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/public/UserClassname")
@Slf4j
public class UserClassnameController {

    @Autowired
    private UserClassnameService userClassnameService;

    /**
     * 获取用户与班级关系列表
     */
    @GetMapping
    public Result getUserClassnameList() {
        log.info("获取用户与班级关系列表");

        List<UserClassname> userClassnameList = userClassnameService.getUserClassnameList();
        return Result.success(userClassnameList);
    }

    /**
     * 获取班级对应的用户列表
     */
    @GetMapping("/userList")
    public Result getUserListByClassId(@RequestParam Integer userTypeId, @RequestParam List<Integer> classIdList) {
        log.info("获取班级对应的用户信息");

        List<User> UserClassnameList = userClassnameService.getUserListByClassId(userTypeId, classIdList);
        return Result.success(UserClassnameList);
    }

    /**
     * 获取用户对应的班级列表
     */
    @GetMapping("/classList")
    public Result getClassListByUserId(@RequestParam Integer userId) {
        log.info("获取用户对应的班级列表");

        List<Classname> UserClassnameList = userClassnameService.getClassnameListByUserId(userId);
        return Result.success(UserClassnameList);
    }
}
